<template>
  <div class="increase">
    <button class="reduce" @click="clickAction">-</button>
    <div class="num">{{count}}</div>
    <button class="add" @click="clickAction">+</button>  
  </div>
</template>
<script>
  export default {
    name: 'increase',
    data: function () {
      return {
        count: this.num
      }
    },
    props: {
      num: {
        type: Number,
        default: 1
      }
    },
    methods: {
      clickAction(e) {
        if (e.target.innerHTML == "-") {
          this.count = this.count > 1 ? (this.count - 1) : 1;
        } else {
          this.count++;
        }
        //触发自定义滚事件
        this.$emit("changeNum", this.count)
      }
    }
  }
</script>
<style scoped lang="less">
  .increase {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #cccccc;
    background-color: #f4f4f4;
  }

  button {
    padding: 3px 0;
    border: 0;
    background-color: #f4f4f4;
  }

  .num {
    padding: 3px 0;
    border-left: 1px #cccccc solid;
    border-right: 1px #cccccc solid;
  }
</style>